<template>
  <div class="app-container">
    <el-dialog :title="titleList[flag]+'（'+form.orderNo+'）'" :visible.sync="dialogVisible" width="60%" append-to-body>
      <div style="display: flex;align-items: center;">
        <dict-tag :options="dict.type.sys_order_type" :value="form.orderType"/>
        <dict-tag :options="dict.type.ims_order_status" :value="form.status" style="margin-left: 10px"/>
      </div>
      <el-form ref="form" :model="form" v-loading="loading">
        <div class="myTitle">基本信息</div>
        <el-row :gutter="10">
          <el-col :span="6">
            <el-form-item label="订单编号" prop="orderNo">
              <div>{{ form.orderNo }}</div>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="下单日期" prop="createTime">
              <div>{{ form.createTime }}</div>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="来源平台" prop="orderFrom">
              <dict-tag :options="dict.type.ims_source_platform" :value="form.orderFrom"/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="源平台单号" prop="sourceOrderNo">
              <div>{{ form.sourceOrderNo || '-' }}</div>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="10">
          <el-col :span="6">
            <el-form-item label="发货时间" prop="sendTime">
              <div>{{ form.sendTime || '-' }}</div>
            </el-form-item>
          </el-col>
        </el-row>
        <div>
          <div class="myTitle">商品信息</div>
          <el-table
            :data="form.matPartProductVos"
            max-height="500"
          >
            <el-table-column type="index" label="序号" align="center"/>
            <el-table-column prop="imageUrls" label="图片" align="center">
              <template slot-scope="scope">
                <div v-if="!scope.row.imageUrls||!scope.row.imageUrls.length">暂无</div>
                <div v-for="val in scope.row.imageUrls" style="display: inline-block;margin-right: 10px">
                  <el-image
                    style="width: 60px;height: 60px"
                    :src="val"
                    fit="contain"
                    :preview-src-list="[val]"
                  >
                  </el-image>
                </div>
              </template>
            </el-table-column>
            <el-table-column prop="title" label="商品/套餐名称" align="center"/>
            <el-table-column prop="skuName" label="商品规格" align="center"/>
            <el-table-column prop="priceType" label="类型" align="center" width="100px">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.ats_price_type" :value="scope.row.priceType"/>
              </template>
            </el-table-column>
            <el-table-column prop="unitPrice" label="单价(元)" align="center" width="100px"/>
            <el-table-column prop="quantity" label="数量" align="center" width="100px"/>
            <el-table-column prop="fileUrl" label="客户图纸" align="center" width="150">
              <template slot-scope="scope">
                <el-link v-if="scope.row.cusFileUrl" type="primary" @click="downloadFile(scope.row.cusFileUrl)">
                  {{ scope.row.cusFileName }}
                </el-link>
                <div v-else>-</div>
              </template>
            </el-table-column>
            <el-table-column prop="fileUrl" label="工厂图纸" align="center" v-if="isSaler" width="150">
              <template slot-scope="scope">
                <el-link v-if="scope.row.fileUrl" type="primary" @click="downloadFile(scope.row.fileUrl)">
                  {{ scope.row.fileName }}
                </el-link>
                <div v-else>-</div>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div>
          <div class="myTitle">收件人信息</div>
          <el-row :gutter="10">
            <el-col :span="6">
              <el-form-item label="快递公司" prop="expressName">
                <div>{{ form.expressName || '-' }}</div>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="快递单号" prop="expressNo">
                <div>{{ form.expressNo || '-' }}</div>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="重量(kg)" prop="weight">
                <div>{{ form.weight || '-' }}</div>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="10">
            <el-col :span="24">
              <el-form-item label="收件人信息" prop="recipientContent">
                <div>{{ form.recipientContent || '-' }}</div>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="10">
            <el-col :span="6">
              <el-form-item label="姓名" prop="recipient">
                <div>{{ form.recipient || '-' }}</div>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="电话" prop="recipientTel">
                <div>{{ form.recipientTel || '-' }}</div>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="详细地址" prop="fullName">
                <div>{{ form.fullName || '-' }}</div>
              </el-form-item>
            </el-col>
          </el-row>
        </div>
        <div>
          <div class="myTitle">付款信息</div>
          <el-row :gutter="10">
            <el-col :span="6">
              <el-form-item label="商品价格(元)" prop="goodsPrice">
                <div>{{ form.goodsPrice }}</div>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="配件价格(元)" prop="matPartPrice">
                <div>{{ form.matPartPrice }}</div>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="快递价格(元)" prop="expressPrice">
                <div>{{ form.expressPrice }}</div>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="其它费用(元)" prop="otherPrice">
                <div>{{ form.otherPrice }}</div>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="合计(元)" prop="totalPrice">
                <div>{{ form.totalPrice }}</div>
              </el-form-item>
            </el-col>
          </el-row>
        </div>
        <el-row :gutter="10">
          <el-col :span="12">
            <el-form-item label="备注" prop="remark">
              <el-input v-if="flag==1" type="textarea" v-model="form.remark" placeholder="请输入"/>
              <div v-else>{{ form.remark || '-' }}</div>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="10">
          <el-col :span="12">
            <el-form-item label="出单备注" prop="printRemark">
              <el-input v-if="flag==1" type="textarea" v-model="form.printRemark" placeholder="请输入"/>
              <div v-else>{{ form.printRemark || '-' }}</div>
            </el-form-item>
          </el-col>
        </el-row>
        <div v-if="flag==1||form.event">
          <div class="myTitle">审核信息</div>
          <el-row :gutter="10">
            <el-col :span="8">
              <el-form-item label="审核结果" prop="event" required>
                <el-select v-if="flag==1" v-model="form.event" filterable style="width: 100%">
                  <el-option
                    v-for="item in dict.type.sys_approve_result"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
                </el-select>
                <dict-tag v-else :options="dict.type.sys_approve_result" :value="form.event"/>
              </el-form-item>
            </el-col>
            <el-col :span="16">
              <el-form-item label="审核意见" prop="reviewDesc" :required="form.result==1">
                <el-input v-if="flag==1" type="textarea" v-model="form.reviewDesc" placeholder="请输入"/>
                <div v-else>{{ form.reviewDesc || '-' }}</div>
              </el-form-item>
            </el-col>
          </el-row>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible=false">取 消</el-button>
        <el-button type="primary" v-if="flag==1" @click="dialogOk">审 核</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  approveOrder,
  getCustomOrder,
} from "../../../api/imsMng";

export default {
  dicts: ['ims_order_status', 'ims_source_platform', 'sys_approve_result', 'ats_price_type', 'sys_order_type'],
  data() {
    return {
      flag: 0,//0详情，1审核
      loading: false,
      titleList: ['详情', '审核'],
      isSaler: 0, //销售
      dialogVisible: false,
      form: {}
    }
  },
  //orderType:10定制，20现货
  methods: {
    show(form, flag) {
      this.flag = flag || 0
      this.dialogVisible = true
      this.form = {}
      this.resetForm('form')
      this.isSaler = form.isSaler || 0
      this.getOrderDetail(form.id)
    },
    getOrderDetail(id) {
      this.loading = true
      getCustomOrder(id).then(res => {
        this.form = res.data
      }).finally(e => {
        this.loading = false
      })
    },
    downloadFile(url) {
      window.open(url)
    },
    dialogOk() {
      this.$refs.form.validate(e => {
        if (e) {
          let req = {
            id: this.form.id,
            event: this.form.event,
            reviewDesc: this.form.reviewDesc,
            remark: this.form.remark,
            printRemark: this.form.printRemark
          }
          this.loading = true
          approveOrder(req).then(res => {
            this.$emit('ok')
            this.dialogVisible = false
            this.$message.success('审核成功')
          }).finally(e => {
            this.loading = false
          })
        }
      })
    }
  }
}
</script>
